package com.ymttest.database.sqlwapper.hunter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.hunter.GiftBagFeeConfig;

public class GiftBagFeeConfigWrapper {

	SqlManager manager;

	public GiftBagFeeConfigWrapper() {
		manager = new SqlManager("tradingsettlement");
	}

	@SuppressWarnings("unchecked")
	public GiftBagFeeConfig selectByPrimaryKey(Long id) {

		GiftBagFeeConfig giftBagFeeConfig = new GiftBagFeeConfig();
		List<GiftBagFeeConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.hunter.GiftBagFeeConfigMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			giftBagFeeConfig = result.get(0);
		}

		return giftBagFeeConfig;
	}

	// 通过费用类型、当前和子hunter等级获取费用信息
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List<GiftBagFeeConfig> selectConfigByTypeAndHunterLevel(int feeType,
			int currentHunterLevel, int childHunterLevel) {
		
		Map m = new HashMap<String, String>();

		m.put("fee_type", feeType);
		m.put("current_hunter_level", currentHunterLevel);
		m.put("child_hunter_level", childHunterLevel);

		List<GiftBagFeeConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.hunter.GiftBagFeeConfigMapper.selectConfigByTypeAndHunterLevel",
						m);
		manager.commit();

		return result;
	}

	public static void main(String[] args) {

		GiftBagFeeConfigWrapper test = new GiftBagFeeConfigWrapper();
		GiftBagFeeConfig giftBagFeeConfig = new GiftBagFeeConfig();
		BigDecimal price = new BigDecimal("350");
		
		List<GiftBagFeeConfig> list = test.selectConfigByTypeAndHunterLevel(0, 1, 0);
		
		for (GiftBagFeeConfig config : list) {
			if (config.getPrice_level().compareTo(price) == 0 || config.getPrice_level().compareTo(price) == -1) {
			
				giftBagFeeConfig = config;
				break;
			}
		}
		
		System.out.println(giftBagFeeConfig.getAmount());
	}
}
